package tesis.utils;

import tesis.common.utils.StringUtil;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author otto.theo
 */
public final class DateUtil {

    private static final Logger LOG = LoggerFactory.getLogger(DateUtil.class);
    public static final String DD_MM_YYYY = "dd/MM/yyyy";
    public static final String DD_MM_YYYY_HHMM = "dd/MM/yyyy hh:mm a";
    public static final SimpleDateFormat FORMAY_DD_MM_YYYY = new SimpleDateFormat(DD_MM_YYYY);
    public static final SimpleDateFormat FORMAT_DD_MM_YYYY_HH = new SimpleDateFormat(DD_MM_YYYY_HHMM);

    private DateUtil() {
    }

    public static String formatDDMMYYYY(Date date) {
        return FORMAY_DD_MM_YYYY.format(date);
    }

    public static Date parseDDMMYYYY(String string) {
        try {
            if (!StringUtil.isEmpty(string)) {
                return DateUtil.FORMAY_DD_MM_YYYY.parse(string);
            }
        } catch (ParseException ex) {
            LOG.warn("No se pudo parsear: " + string + " a fecha", ex);
        }
        return null;
    }
    public static String formatDDMMYYHH(Date date){
        return FORMAT_DD_MM_YYYY_HH.format(date);
    }
}
